import { protectedRequest } from './index';
const request = protectedRequest();

/**
 * 获取orders列表
 */
const orderListReq = () => request({
  method: 'get',
  url: `/order/list`,
});

/**
 * 根据clientId获取未送货的orders列表
 */
const orderListByClientIdReq = (clientId) => request({
  method: 'get',
  url: `/order/list/${clientId}`
});

/**
 * 为id为clientId的客户添加订单
 * @param {number} clientId 
 * @param {Array} orders 
 */
const orderAppendReq = (clientId, orders) => request({
  method: 'post',
  url: `/order/append/${clientId}`,
  data: {
    orders
  }
});

/**
 * 通过orderId获得order的request请求
 * @param {number} orderId 
 */
const orderCheckReq = (orderId) => request({
  method: 'get',
  url: `/order/check/${orderId}`,
});

/**
 * 通过orderId修改order的request请求
 * @param {number} orderId 
 * @param {Object} order
 */
const orderUpdateReq = (orderId, order) => request({
  method: 'put',
  url: `/order/update/${orderId}`,
  data: order
});

/**
 * 通过orderId修改order的request请求，该order已送货
 * @param {number} orderId 
 * @param {Object} order
 */
const orderUpdateDeliveredReq = (orderId, order) => request({
  method: 'put',
  url: `/order/updateDelivered/${orderId}`,
  data: order
});

/**
 * 通过orderId删除order的request请求
 * @param {number} orderId 
 */
const orderDelReq = (orderId) => request({
  method: 'delete',
  url: `/order/delete/${orderId}`,
});

export {
  orderListReq,
  orderListByClientIdReq,
  orderCheckReq,
  orderAppendReq,
  orderUpdateReq,
  orderUpdateDeliveredReq,
  orderDelReq
}
